package com.dst.smart.dao.impl.factory;

import java.util.ArrayList;
import java.util.List;

import com.dst.smart.app.MyApplication;
import com.dst.smart.model.Products;

public class ProductFactory {
	public static List<Products> list = new ArrayList<Products>();

	static {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getProducts();
		}
	}

	public static List<Products> getAll() {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getProducts();
		}
		return list;
	}

	public static List<Products> getProduct(int id, int products_version) {
		List<Products> resultList = new ArrayList<Products>();
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getProducts();
		}

		for (Products products : list) {
			if (products.getProducts_Id() == id
					&& (products.getProducts_version() == products_version)) {
				resultList.add(products);
			}
		}
		return resultList;
	}

	public static void clearList() {
		list = MyApplication.getInstance().getWidgetDataBase().getProducts();
	}
}
